# -*- coding: utf-8 -*-

import codecs
from wiktionary_parser.xml_parser import XMLPageParser
from wiktionary_parser.languages.de.page import dePage

nzqa_file = codecs.open('../../wiktionary_data/nzqa_german_list1.txt', 'r', 'utf16')
xml_file = open('/Users/Ben/Web/wiktionary_data/dewiktionary-20100401-pages-articles.xml')
xml_parser = XMLPageParser(xml_file, dePage)

def clean(word):
    return word.lstrip(' \r\n').rstrip(' \r\n')

german_words = []
for line in nzqa_file:
    words = line.split('\t')
    # If not a title print german word
    article, german, english = [clean(word) for word in words]
    if not english:
        continue
    german_words.append(german)

german_words = [u'März']

found_words = set([])
for title, page in xml_parser.from_titles(german_words):
    found_words.add(title)
    page.parse()
    for word in page.words:
        print word.title
        if False:
            if word.bedeutungen:
                print '-----------------'
                print word.bedeutungen
            if word.beispiele:
                print '-----------------'
                print word.beispiele
            print '******************'
    alerts = page.get_all_alerts()
    if alerts:
        print alerts
        

unfound_words = set(german_words) - found_words
print unfound_words
